<?php

	/* SVN FILE: $Id: unita_suggestions.php 43 2011-01-16 22:16:50Z andreoletti $ */
	
	/**
	 * Project Name : arcadia
	 *
	 * @author $Author: andreoletti $
	 * @version $Revision: 43 $
	 * @lastrevision $Date: 2011-01-16 23:16:50 +0100 (dom, 16 gen 2011) $
	 * @filesource $URL: http://svn.fletchlynd.com/arcadia/trunk/visioni/unita_suggestions.php $
	 */
	 
	require_once 'include/functions.php';
	require_once 'include/const.inc.php';
	require_once '../include/auth.inc.php';
	require_once '../include/conn.inc.php';
	
	$aItems = array();

	fnGetValueFromGET(array('term'));
	
	if (!isset($sViewItemLink) || empty ($sViewItemLink)) {
		$sViewItemLink = $aTABLE[$sTABLE_DEFAULT]['sViewItemLink'];
	}
	
	fnViewConst($sViewItemLink);
	
	if (isset($term) && !empty($term))
		$sQuery = "	SELECT `us`.`sDescription`, `sEmail`.`sValue` AS `sEmail`
					FROM `resources` `us` 
					LEFT OUTER JOIN `properties` `sEmail` ON `us`.`id` = `sEmail`.`iTable` AND `sEmail`.`sSelectFrom` = 'resources' AND `sEmail`.`sField` = 'sEmail' 			
					WHERE `us`.`sType`='US' AND `iShow`='1' AND `us`.`sDescription` LIKE '%$term%' GROUP BY `us`.`id` ORDER BY `us`.`sDescription`";
	else
		$sQuery = "	SELECT `us`.`sDescription`, `sEmail`.`sValue` AS `sEmail`
					FROM `resources` `us` 
					LEFT OUTER JOIN `properties` `sEmail` ON `us`.`id` = `sEmail`.`iTable` AND `sEmail`.`sSelectFrom` = 'resources' AND `sEmail`.`sField` = 'sEmail' 			
					WHERE `us`.`sType`='US' AND `iShow`='1' GROUP BY `us`.`id` ORDER BY `us`.`sDescription`";
	
	if (isset($sQuery) && !empty($sQuery)){
		$rResult = custom_mysql_query ($sQuery);
		while ($aRow = mysql_fetch_array ($rResult)) {
			$aItems[] = array("value" => strip_tags($aRow['sDescription']), "sEmail" => strip_tags($aRow['sEmail']));
		}
	}

	echo array_to_json($aItems);
	die();
?>

